
import wx
import wx.lib.scrolledpanel as scrolled
import time
import queue
class LoggerPanel(scrolled.ScrolledPanel):
    lines = []
    def __init__(self, parent, pos, size):
        self.size = size
        scrolled.ScrolledPanel.__init__(self, parent, -1, pos = pos, size=size)

        self.vbox = wx.BoxSizer(wx.HORIZONTAL)

        self.logout = wx.StaticText(self, -1, "", pos = pos, size=(size[0], size[1]+300))
        # self.logout = wx.TextCtrl ( self, value = "Test", style = wx.TE_READONLY) 
        self.logout.SetForegroundColour("White")
        self.vbox.Add(self.logout, 0, wx.ALIGN_LEFT | wx.ALL, 5)
        self.SetBackgroundColour("Black")
        self.SetSizer(self.vbox)
        self.SetupScrolling()

    def log(self, txt):
        line = f"[{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())}] "
        line += txt
        line += "\n"
        if len(self.lines) > 16:
            self.lines.pop(0)
        self.lines.append(line)
        self.logout.SetLabel("".join(self.lines))
        self.size = (self.size[0],self.size[1] + 20)
        self.logout.SetSize(self.size)
        self.logout.Update()
        self.SetSizer(self.vbox, deleteOld=True)
        self.Update()
